<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>美食</title>

<style type="text/css">
#user_fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
}
</style>


<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/color.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>


<div class="tableFind">
            <p> <label>美食名称</label>&nbsp;&nbsp;
				<input type="text" id="foodName"  onkeydown="if(event.keyCode==13) searchMessage()"/> 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            
           <a id="btn"
					href="javascript:searchfood()" class="easyui-linkbutton tableFindBut"
					data-options="iconCls:'icon-search'" onclick="obj.find()">查询	
			  </a></p>
        </div>
	
	<table id="user_dg" class="easyui-datagrid" style="height: 470px;"
		url="${pageContext.request.contextPath}/admin/Food/findAll.do" toolbar="#user_toolbar" pagination="true"
		rownumbers="true" fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>
		
		<!-- 管理表格-表头的修改 -->
			<tr>
               <th field="cb" checkbox="true" align="center"></th>
				<th field="foodNo" width="80" align="center">美食编号</th>
				<th field="foodImg" width="80" align="center">美食图片</th>
				<th field="foodName" width=80 align="center">美食名称</th>

				<!-- <th field="typeNo" width="80" align="center">美食类型编号</th> -->
				<th field="typeNo" formatter="foodFormat" width="80">美食类型</th>
				
				<!-- <th field="makeNo" width="80" align="center">制作类型编号</th> -->
				<th field="makeNo" formatter="makeFormat" width="80">制作类型</th>
				
				<!-- <th field="userNo" width="80" align="center">会员编号</th> -->
				<th field="userNo" formatter="userFormat" width="80">发布作者</th>
				
				<th field="publishTime" width="150" align="center">发布时间</th>
				<th field="state" width="80" align="center">发布状态</th>
			</tr>
		</thead>
	</table>
	<div id="user_toolbar">
	 <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editUserMessage()">编辑</a> 
	</div>

	<div id="user_dlg" class="easyui-dialog" style="padding: 10px 20px";
		closed="true" buttons="#user_dlg-buttons">
		
		<div class="ftitle">详细信息</div>
		<form id="user_fm" method="post" novalidate>
			<div class="fitem">
				<label>美食图片:</label> <input name="foodImg" class="easyui-textbox" readonly="readonly">
			</div>
			<div class="fitem">
				<label>美食名称:</label> <input name="foodName" class="easyui-textbox" readonly="readonly">
			</div>
			<div class="fitem">
				<label>美食类型:</label>
				<input id="id_type"  name="foodType.typeNo" valueField="typeNo"
					textField="type" required="true" editable="false" url="${pageContext.request.contextPath}/admin/FoodType/findList.do"
					class="easyui-combobox" readonly="readonly">
				 
			</div>
			
			<div class="fitem">
				<label>制作类型:</label>
				<input id="id_make"  name="foodMake.makeNo" valueField="makeNo"
					textField="make" required="true" editable="false" url="${pageContext.request.contextPath}/admin/FoodMake/findList.do"
					class="easyui-combobox" readonly="readonly">
				 				 
			</div>
			
			
			<div class="fitem">
				<label>发布作者:</label>
				<input id="id_userMessage"  name="userMessage.userNo" valueField="userNo"
					textField="userName" required="true" editable="false" url="${pageContext.request.contextPath}/UserMessage/findList.do"
					class="easyui-combobox" readonly="readonly">
			</div>
			
			
			<div class="fitem">
				<label>发布日期:</label> <input name="publishTime" class="easyui-datebox" validType="date" readonly="readonly">
			</div>
		    <div class="fitem">
				<label>状态:</label> <input name="state" class="easyui-textbox" required="true">
			</div>
			
		</form>
	</div>
	<div id="user_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveUserMessage()" style="width: 90px">保存</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#user_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	
	
	<!-- <select id="select_percent" class="easyui-combobox" name="dept" style="width:60px;">            
        <option value="合法" >合法</option>  
        <option value="违规">违规</option>
   </select>  
	 -->
	
	
	<script type="text/javascript">
	
	
	

	function searchfood(){
		var foodName = $.trim($('#foodName').val());		//获取搜索框的内，$.trim()可以消除前后空格
		
		if(foodName==""){foodName=null;
		
		}else{
			$('#user_dg').datagrid('load', {
				foodName : $('#foodName').val()
			});
		}	
		
	}
		
		
	
	
	/* //选择框
	$('#select_percent').combobox({  
	    onChange:function(newValue,oldValue){  
	        alert(newValue);  
	});  */ 
	
	/* //模糊查询
	function searchfood() {
		$('#user_dg').datagrid('load', {
			foodName : $('#foodName').val()
		});
	}
	 */
	
	//重新设置easy ui的时间格式
	$.fn.datebox.defaults.formatter=function(date){
		var y=date.getFullYear();
		var m=date.getMonth()+1;
		var d=date.getDate();
		return y+'/'+m+'/'+d;
	}
	$.fn.datebox.defaults.parser=function(date){
		if(date){
			return new Date(date)
		}else{
			return new Date();
		}
	}
	
	
	
	//使用格式化显示数据
	function foodFormat(value, row, rowindex) {
		//用参数 row 来获取foodType对象,再调用里面的type属性
		return row.foodType.type;
	}

	function makeFormat(value, row, rowindex) {
		return row.foodMake.make;
	}
	
	function userFormat(value, row, rowindex) {
		return row.userMessage.userName;
	}
	
	
	
		var url;
		
		function editUserMessage() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$('#user_dlg').dialog('open').dialog('setTitle', '编辑');
				$('#user_fm').form('clear');//清除表单数据
				$('#user_fm').form('load', row);
				url = '${pageContext.request.contextPath}/admin/Food/updateFood.do?foodNo=' + row.foodNo;
			}
			
			
			//console.log(row.provider.providerNo);
			//从已经加载的datagride中所选择的行（row）中获取key值,修改下拉框的选中值  
			var foodTypedata = $('#id_type').combobox('getData');
		    if(foodTypedata.length>0){
		    	//编辑窗口默认选中正在编辑的数据
			  $('#id_type').combobox('select',row.foodType.typeNo);
		    }; 
		    
		    var foodMakedata = $('#id_make').combobox('getData');
		    if(foodMakedata.length>0){
		    	//编辑窗口默认选中正在编辑的数据
			  $('#id_make').combobox('select',row.foodMake.makeNo);
		    }; 
		    
		    var userMessagedata = $('#id_userMessage').combobox('getData');
		    if(userMessagedata.length>0){
			  $('#id_userMessage').combobox('select',row.userMessage.userNo);
		    }; 
		    
		    
		    var foodTypedata = $('#id_typeSearch').combobox('getData');
		    if(foodTypedata.length>0){
		    	//编辑窗口默认选中正在编辑的数据
			  $('#id_typeSearch').combobox('select',row.foodType.typeNo);
		    }; 
		    
		    var foodMakedata = $('#id_makeSearch').combobox('getData');
		    if(foodMakedata.length>0){
		    	//编辑窗口默认选中正在编辑的数据
			  $('#id_makesearch').combobox('select',row.foodMake.makeNo);
		    }; 
		    
			
		}
		function saveUserMessage() {
			$('#user_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$('#user_dlg').dialog('close'); // close the dialog
						$('#user_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}
		function destroyUserMessage() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
					if (r) {
						//ajax调用--异步通信调用
						$.post('usermessage/deleteUserMessage.do', {
							userNo : row.userNo
						}, function(result) {
							if (result.success) {
								$('#user_dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');//回调函数
					}
				});
			}
		}
	</script>

</body>
</html>